//
//  LGDeviceSendViewCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/9.
//

#import "LGDeviceSendViewCell.h"

@interface LGDeviceSendViewCell()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *timeIcon;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UIButton *cancelBtn;
/**   */
@property (nonatomic , strong)UIButton *sendBtn;

@end

@implementation LGDeviceSendViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = LGNSString(dataDic[@"title"]);
    self.statusLabel.text = [dataDic[@"receipt_type"] integerValue] == 0?@"邮寄":@"线下领取";
    NSString *colorStr = [dataDic[@"receipt_type"] integerValue] == 0?@"#3291FF":@"#666666";
    self.statusLabel.textColor = [UIColor colorWithString:colorStr];
    UIImage *placeHolder = [LGNSString(dataDic[@"gender"]) isEqualToString:@"男"]?defaultPatientMan:defaultPatientWomen;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"avatar_url"])] placeholderImage:placeHolder];
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    //性别、年龄
    NSString *age = (LGNSString(dataDic[@"age"]).length>0)?[NSString stringWithFormat:@"%@岁",dataDic[@"age"]]:@"";
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@",dataDic[@"gender"],age];
    self.timeLabel.text = [NSString stringWithFormat:@"%@ - %@",dataDic[@"vip_date_start"],dataDic[@"vip_date_end"]];

}

-(void)cancelBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(cancelSendDeviceAction:index:)]){
        [self.delegate cancelSendDeviceAction:self.dataDic index:self.index];
    }
}

-(void)sendBtnAction{
    
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.headPic];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.timeIcon];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.cancelBtn];
    [self.baseView addSubview:self.sendBtn];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.top.equalTo(self.baseView).offset(viewPix(15));
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.iconView);
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.titleLabel);
    }];
    [self.headPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.iconView);
        make.width.height.equalTo(@(viewPix(32)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.headPic);
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.timeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headPic.mas_bottom).offset(viewPix(12));
        make.left.with.height.equalTo(self.iconView);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeIcon.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.timeIcon);
    }];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeIcon.mas_bottom).offset(viewPix(13));
        make.right.equalTo(self.sendBtn.mas_left).offset(-viewPix(12));
        make.width.equalTo(@(viewPix(74)));
        make.height.equalTo(@(viewPix(32)));
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
    }];
    [self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.width.height.equalTo(self.cancelBtn);
    }];
}

-(UIView*)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"设备发货-设备名称"]];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _statusLabel;
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]init];
        _headPic.cornerRidus = 4;
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)timeIcon{
    if(!_timeIcon){
        _timeIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"设备发货-时间"]];
    }
    return _timeIcon;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UIButton *)cancelBtn{
    if(!_cancelBtn){
        _cancelBtn = [UIButton buttonWithTitle:@"取消" titleFont:LGFontWeight(14, UIFontWeightMedium) textColor:@"#EB5757" imageName:@""];
        _cancelBtn.layer.borderColor = [UIColor colorWithString:@"#EB5757"].CGColor;
        _cancelBtn.layer.borderWidth = 1;
        _cancelBtn.cornerRidus = viewPix(16);
        [_cancelBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

-(UIButton *)sendBtn{
    if(!_sendBtn){
        _sendBtn = [UIButton buttonWithTitle:@"发货" titleFont:LGFontWeight(14, UIFontWeightMedium) textColor:@"#FFFFFF" imageName:@""];
        _sendBtn.backgroundColor = [UIColor colorWithString:@"#3291FF"];
        _sendBtn.cornerRidus = viewPix(16);
        _sendBtn.userInteractionEnabled = NO;
//        [_sendBtn addTarget:self action:@selector(sendBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sendBtn;
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
